﻿#include "mycommon.h"
#include <QAndroidJniEnvironment>
#include <QAndroidJniObject>
#include <QtAndroid>
#include <QDebug>
#include <QException>

MyCommon::MyCommon(QObject *parent) : QObject(parent)
{

}

void MyCommon::addQQ(const QString &qq)
{

    QAndroidJniObject action = QAndroidJniObject::fromString("mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26k%3D" + qq);


    QAndroidJniObject intent("android/content/Intent");

    jint result = QAndroidJniObject::callStaticMethod<jint>("an/qt/useJar/ExtendsQtWithJava",
                                              "addQQ",
                                              "(Ljava/lang/String;)I",
                                              action.object<jstring>());

    if(result == 1){
        qDebug("sucess");
    }
    else{
        qDebug("fail");
    }

}

void MyCommon::saveScore(double score)
{
    QSettings settings(QDir::currentPath()+"/data.ini", QSettings::IniFormat);
    settings.setValue("config/score", score);
}

double MyCommon::getScore()
{
    QSettings settings(QDir::currentPath()+"/data.ini", QSettings::IniFormat);
    double score = 0.0;
    score = settings.value("config/score").toDouble();

    return score;
}

